import { scrollMixin } from "utils/mixin";
export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {},
  mixins: [scrollMixin], //加载更多
  data() {
  return {
    active:0,
    isLoadMore: true,
    page: 1,
    total_page: 0,
    infoEnergy:{},
    energyList:[],
    bonusList:[]
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    loveOn() {
     this.$router.push(this.fun.getUrl("contribution", {}, {}));
      // this.$router.push(this.fun.getUrl("love_list", {}, {}));
    },
    energyTab(event) {
      console.log(event);
      this.page = 1;
      this.active = event;
      this.energyList = [];
      if(this.active === 0) {
        this.api = 'plugin.energy-pool.frontend.controllers.center.energy';
      } else {
        this.api = 'plugin.energy-pool.frontend.controllers.center.pool'
      }
      this.energyData();
    },
    energyData() {
      $http.get(this.api, {page: this.page,basic_info:1}, "加载中..").then(response => {
        if (response.result == 1) {
          let basicInfo = response.basic_info;
          let res = response.data;
          this.energyList = res.list?.data;
          this.infoEnergy = res.info;
          this.isLoadMore = true;
          this.total_page = res.list?.last_page;
          if (!this.total_page) {
            this.page = 0;
          }
          this.$nextTick(() => {
            this.fun.wxShare(
              "",
              { mid: this.fun.getKeyByMid() },
              {
                url: window.location.href,
                title: basicInfo?.home.mailInfo?.name,
                imgUrl: basicInfo?.home.mailInfo?.logo_url,
                description: ''
              }
            );
          },50);
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
     //获取更多数据
     getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        if(this.active === 0) {
          this.api = 'plugin.energy-pool.frontend.controllers.center.energy';
        } else {
          this.api = 'plugin.energy-pool.frontend.controllers.center.pool';
        }
        $http.post(this.api, { page: this.page }, "加载中").then(
          res => {
            this.isLoadMore = true;
            if (res.result === 1) {
              console.log(res.data);
              let myData = res.data.list?.data;
              this.energyList = [...this.energyList, ...myData]; //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            // error callback
          }
        );
      }
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    if(this.active === 0) {
      this.api = 'plugin.energy-pool.frontend.controllers.center.energy';
    } else {
      this.api = 'plugin.energy-pool.frontend.controllers.center.pool'
    }
    this.energyData();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
}